package shuailong;

import java.io.*;

/**
 * Created by zzy on 2018/1/17.
 */
public class fileTransfer {

    public static void main(String[] args) throws IOException {
        File sourceFolder=new File("G:/英雄时刻/java");
        File[] files=sourceFolder.listFiles(new JavaFileFilter());
        for(File file:files){
            String absolutePath=file.getName();
            String targetFile="G:/英雄时刻/jad/"+absolutePath.substring(0,absolutePath.length()-5)+".jad";
            File target=new File(targetFile);
            //file.renameTo(target);
            copy(file,new File(targetFile));
        }
    }


    private static void copy(File source,File target) throws IOException {
        FileInputStream input=new FileInputStream(source);
        FileOutputStream out=new FileOutputStream(target);
        int length=-1;
        byte[] bs=new byte[1024];
        while ((length=input.read(bs))!=-1){
            out.write(bs,0,length);
        }
        input.close();
        out.close();
    }

    /**
     * 文件过滤
     */
    private static final class JavaFileFilter implements FilenameFilter{

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".java");
        }
    }
}
